import { http } from "@/utils/http";

export const useSongAPI = () => {
  const getAllSongType = (): any => {
    return http.get(`/music/type/all`);
  };

  // 获取推荐歌曲列表
  const getAllSongs = (uid: string, page: number): any => {
    return http.get(`/music/queryOrderAll?uid=${uid}&page=${page}&rows=${18}`);
  };

  // 收藏音乐
  const getCollectSong = (songId: string, userId: string): any => {
    return http.get(`/favor/addFavor?musicId=${songId}&collectorId=${userId}`);
  };

  // 取消收藏音乐
  const getCancelCollectSong = (songId: string, userId: string): any => {
    return http.get(
      `/favor/cancelFavor?musicId=${songId}&collectorId=${userId}`
    );
  };

  // 添加播放记录
  const addPlayRecord = (userId: string, musicId: string): any => {
    return http.post(`/user/playRecord/add`, {
      userId,
      musicId,
    });
  };

  // 获取用户收藏的歌曲ID列表
  const getFavoriteSongs = (userId: string): any => {
    return http.get(`/music/favor/queryById?id=${userId}`);
  };

  // 获取歌曲详情
  const getSongDetail = (musicId: string): any => {
    return http.get(`/music/queryByMusicId?id=${musicId}`);
  };

  // 添加歌曲到歌单
  const addSongToPlaylist = (songId: string, playlistId: string): any => {
    return http.post(`/music/playlists/${playlistId}/songs/${songId}`);
  };

  // 查询用户对歌曲的收藏状态
  const checkSongFavorStatus = (userId: string, musicId: string): any => {
    return http.get(`/favor/queryFavor?userId=${userId}&musicId=${musicId}`);
  };

  return {
    getAllSongType,
    getAllSongs,
    getCollectSong,
    getCancelCollectSong,
    addPlayRecord,
    getFavoriteSongs,
    getSongDetail,
    addSongToPlaylist,
    checkSongFavorStatus,
  };
};
